package biz.microplus.information.bean;

import biz.microplus.information.common.DateUtil;

import javax.persistence.Entity;
import javax.persistence.Id;

/**
 * 账户数据模型
 */
@Entity
public class UserBean extends BaseBean{

    public UserBean(){}

    public UserBean(String username, String password, String email, int groupId){
        this.username = username;
        this.password = password;
        this.email = email;
        this.groupId = groupId;
        this.createdAt = DateUtil.getNowTimestamp();
        this.lastLogin = 0;
        this.previousLogin = 0;
        this.loginHash = "";
    }

    /**
     * 标识
     */
    @Id
    private int id;
    /**
     * 用户名
     */
    private String username;
    /**
     * 密码
     */
    private String password;
    /**
     * 用户组ID
     */
    private int groupId;
    /**
     * 角色名称
     */
    private String roleName;
    /**
     * 邮箱地址
     */
    private String email;
    /**
     * 最后登录时间戳
     */
    private int lastLogin;
    /**
     * 上次登录时间戳
     */
    private int previousLogin;
    /**
     * 登录Hash
     */
    private String loginHash;
    /**
     * 操作人ID
     */
    private int userId;
    /**
     * 注册时间戳
     */
    private int createdAt;
    /**
     * 更新时间戳
     */
    private int updatedAt;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getGroupId() {
        return groupId;
    }

    public void setGroupId(int groupId) {
        this.groupId = groupId;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public int getLastLogin() {
        return lastLogin;
    }

    public void setLastLogin(int lastLogin) {
        this.lastLogin = lastLogin;
    }

    public int getPreviousLogin() {
        return previousLogin;
    }

    public void setPreviousLogin(int previousLogin) {
        this.previousLogin = previousLogin;
    }

    public String getLoginHash() {
        return loginHash;
    }

    public void setLoginHash(String loginHash) {
        this.loginHash = loginHash;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public int getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(int createdAt) {
        this.createdAt = createdAt;
    }

    public int getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(int updatedAt) {
        this.updatedAt = updatedAt;
    }

    public String getRoleName() {
        if(this.groupId ==  3){
            this.roleName = "会员";
        }else if(this.groupId ==  4){
            this.roleName = "厂家";
        }else if(this.groupId ==  4){
            this.roleName = "平台";
        }
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    @Override
    public String toString(){
        return "{\"id\": 0, \"name\": \"admin\"}";
    }

}